
function  $(ele) {
    let res = document.querySelectorAll(ele);
    return res.length == 1 ? res[0] : res;
}
//手机号
let t=false;
let phone=$('#tel');
let ev=$('#a1');
let ft=$('#a1-1')
phone.oninput=()=>{
    let  flg=/^.{4,11}$/.test(phone.value);
    
    if(flg){
        t=flg;
        ev.innerHTML='输入正确'
        ev.style.color="green";
        ft.style.color="green"
    }else{
        ev.innerHTML='输入有误,请重新输入';
        ev.style.color="red";
        ft.style.color="red"
    }
}
//手机号
let y=false;
let zh=$('#code');
console.log(zh);
let gh=$('#f')
zh.oninput=()=>{
    let  flg=/^.{4,11}$/.test(zh.value);
    
    if(flg){
        console.log(222);
        y=flg;
        gh.innerHTML='输入正确'
        gh.style.color="green";

    }else{
        console.log(111);
        gh.innerHTML='输入有误,请重新输入';
        gh.style.color="red";
    }
}
//密码
let u=false;
let psw=$('#psw');
let bv=$('#a2-1');
psw.oninput=()=>{
    let  flg=/^\d{4,11}$/.test(psw.value);
    
    if(flg){
        u=flg;
        bv.innerHTML='输入正确'
        bv.style.color="green";
        // ft.style.color="green"
    }else{
        bv.innerHTML='输入有误,请重新输入';
        bv.style.color="red";
        // ft.style.color="red"
    }
}
//确认密码
let req=$('#repsw');
let as=$('#a3-1')
let p=false;
req.oninput=()=>{
    if(req.value==psw.value){
        p=true;
        as.innerHTML='输入正确'
        as.style.color="green";
    }else{
        as.innerHTML='输入有误,请重新输入';
        as.style.color="red";
    }
}
//复选框
let rea=$('#che');
console.log(rea);
let ad=$('#opg')
rea.onclick=()=>{
    if(rea.checked){ 
        console.log(777);
        ad.innerHTML='成功';
        ad.style.color="green";
    }else{
        console.log(888);
        ad.innerHTML='请勾选复选框';
        ad.style.color="red";
    }
}
// 判断是否全部为true
let btn=$('.over');
btn.onclick=async ()=>{
    if(u&&t&&p&&y&&rea.checked){
        var name=$('#code').value.trim();
        var sh=$('#tel').value.trim();
        let mi=$('#psw').value.trim()
        var qr=$('#repsw').value.trim()
        adm=`username=${name}&password=${mi}&rpassword=${qr}&nickname=${sh}`;
        console.log(adm);
        //请求头
        axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        let {data,status}  = await axios({
            url:"http://localhost:8888/users/register",
            method:"post",
            data:adm
        }) 
        console.log(data.code,status);
        if(data.code==1,status==200){
            alert('注册成功,即将跳转登录页面')
        }
        location.href='./login.html'
    
    }else{
        alert('请检查表单')
    }
}



